Return to start page

Systems/Character/Struct Characters Scheme.j

Code

		
1			library AStructSystemsCharacterCharactersScheme requires optional ALibraryCoreDebugMisc, ALibraryCoreGeneralPlayer, AStructCoreInterfaceMultiboardBar, ALibraryCoreInterfaceMisc, ALibraryCoreInterfaceMultiboard, AStructSystemsCharacterCharacter
2
3 struct ACharactersScheme
4 //static start members
5 private static real m_refreshRate
6 private static integer m_barLength
7 private static string m_textTitle
8 private static string m_textLevel
9 private static string m_textLeftGame
10 //static members
11 private static trigger m_refreshTrigger
12 private static multiboard m_multiboard
13 private static AMultiboardBar array m_experienceBar[12] //bj_MAX_PLAYERS /// @todo vJass bug
14 private static AMultiboardBar array m_hitPointsBar[12] //bj_MAX_PLAYERS /// @todo vJass bug
15 private static AMultiboardBar array m_manaBar[12] //bj_MAX_PLAYERS /// @todo vJass bug
16 private static integer m_maxPlayers
17
18 //! runtextmacro optional A_STRUCT_DEBUG("\"ACharactersScheme\"")
19
20 private static method create takes nothing returns thistype
21 return 0
22 endmethod
23
24 private method onDestroy takes nothing returns nothing
25 endmethod
26
27 private static method triggerActionRefresh takes nothing returns nothing
28 local integer i
29 local multiboarditem multiboardItem
30 local player user
31 set i = 0
32 loop
33 exitwhen (i == thistype.m_maxPlayers)
34 set multiboardItem = MultiboardGetItem(thistype.m_multiboard, i, 0)
35 set user = Player(i)
36 if ((IsPlayerPlayingUser(user) and ACharacter.playerCharacter(user) != 0) or (ACharacter.shareOnPlayerLeaves() and ACharacter.playerCharacter(user) != 0)) then
37 //refresh name (class - unit name) - level
38 call MultiboardSetItemValue(multiboardItem, GetModifiedPlayerName(user) + " [" + GetUnitName(ACharacter.playerCharacter(user).unit()) + "] - " + thistype.m_textLevel + " " + I2S(GetHeroLevel(ACharacter.playerCharacter(user).unit())))
39
40 if (IsUnitAliveBJ(ACharacter.playerCharacter(user).unit())) then
41 if (IsUnitType(ACharacter.playerCharacter(user).unit(), UNIT_TYPE_HERO)) then
42 call thistype.m_experienceBar[i].setValue(GetHeroXP(ACharacter.playerCharacter(user).unit()))
43 call thistype.m_experienceBar[i].setMaxValue(100000) /// @todo Calculate max experience per level
44 call thistype.m_experienceBar[i].refresh()
45 endif
46
47 call thistype.m_hitPointsBar[i].setValue(GetUnitState(ACharacter.playerCharacter(user).unit(), UNIT_STATE_LIFE))
48 call thistype.m_hitPointsBar[i].setMaxValue(GetUnitState(ACharacter.playerCharacter(user).unit(), UNIT_STATE_MAX_LIFE))
49 call thistype.m_hitPointsBar[i].refresh()
50
51 call thistype.m_manaBar[i].setValue(GetUnitState(ACharacter.playerCharacter(user).unit(), UNIT_STATE_MANA))
52 call thistype.m_manaBar[i].setMaxValue(GetUnitState(ACharacter.playerCharacter(user).unit(), UNIT_STATE_MAX_MANA))
53 call thistype.m_manaBar[i].refresh()
54 else
55 call thistype.m_hitPointsBar[i].setValue(0)
56 call thistype.m_hitPointsBar[i].setMaxValue(1)
57 call thistype.m_hitPointsBar[i].refresh()
58 call thistype.m_manaBar[i].setValue(0)
59 call thistype.m_manaBar[i].setMaxValue(1)
60 call thistype.m_manaBar[i].refresh()
61
62 endif
63 elseif (thistype.m_hitPointsBar[i] != 0) then
64 call MultiboardSetItemValue(multiboardItem, thistype.m_textLeftGame)
65
66 call thistype.m_experienceBar[i].destroy()
67 set thistype.m_experienceBar[i] = 0
68 call thistype.m_hitPointsBar[i].destroy()
69 set thistype.m_hitPointsBar[i] = 0
70 call thistype.m_manaBar[i].destroy()
71 set thistype.m_manaBar[i] = 0
72 endif
73 call MultiboardReleaseItem(multiboardItem)
74 set multiboardItem = null
75 set i = i + 1
76 endloop
77 endmethod
78
79 private static method createRefreshTrigger takes nothing returns nothing
80 local event triggerEvent
81 local triggeraction triggerAction
82 set thistype.m_refreshTrigger = CreateTrigger()
83 set triggerEvent = TriggerRegisterTimerEvent(thistype.m_refreshTrigger, thistype.m_refreshRate, true)
84 set triggerAction = TriggerAddAction(thistype.m_refreshTrigger, function thistype.triggerActionRefresh)
85 call DisableTrigger(thistype.m_refreshTrigger)
86 set triggerEvent = null
87 set triggerAction = null
88 endmethod
89
90 /// Call this AFTER character creation/character class selection
91 private static method createMultiboard takes nothing returns nothing
92 local integer i
93 local player user
94 local multiboarditem multiboardItem
95 set thistype.m_multiboard = CreateMultiboard()
96 call MultiboardSetTitleText(thistype.m_multiboard, thistype.m_textTitle)
97 call MultiboardSetColumnCount(thistype.m_multiboard, 12) /// @todo Preset correct column count
98 call MultiboardDisplay(thistype.m_multiboard, false)
99 set i = 0
100 loop
101 exitwhen (i == bj_MAX_PLAYERS)
102 set user = Player(i)
103 if (ACharacter.playerCharacter(user) != 0) then
104 call MultiboardSetRowCount(thistype.m_multiboard, MultiboardGetRowCount(thistype.m_multiboard) + 1)
105 set multiboardItem = MultiboardGetItem(thistype.m_multiboard, i, 0)
106 call MultiboardSetItemWidth(multiboardItem, 0.35) /// @todo check it
107 call MultiboardSetItemStyle(multiboardItem, true, false)
108 call MultiboardReleaseItem(multiboardItem)
109 set multiboardItem = null
110
111 set thistype.m_experienceBar[i] = AMultiboardBar.create(thistype.m_multiboard, 1, i, 10, 0.0, true, 0.0, 0.0, 0, 0)
112 call thistype.m_experienceBar[i].setAllIcons("Icons\\Interface\\Bars\\White.blp", false) //empty icons
113 call thistype.m_experienceBar[i].setAllIcons("Icons\\Interface\\Bars\\Purple.blp", true)
114
115 set multiboardItem = MultiboardGetItem(thistype.m_multiboard, i, thistype.m_experienceBar[i].firstFreeField())
116 //call MultiboardSetItemWidth(multiboardItem, 0.08) /// @todo check it
117 call MultiboardSetItemStyle(multiboardItem, false, true)
118 call MultiboardReleaseItem(multiboardItem)
119 //set separator icon
120 set multiboardItem = null
121
122 set thistype.m_hitPointsBar[i] = AMultiboardBar.create(thistype.m_multiboard, thistype.m_experienceBar[i].firstFreeField() + 1, i, 10, 0.0, true, 0.0, 0.0, 0, 0)
123 call thistype.m_hitPointsBar[i].setAllIcons("Icons\\Interface\\Bars\\White.blp", false) //empty icons
124 call thistype.m_hitPointsBar[i].setAllIcons("Icons\\Interface\\Bars\\Green.blp", true)
125
126 set multiboardItem = MultiboardGetItem(thistype.m_multiboard, i, thistype.m_hitPointsBar[i].firstFreeField())
127 //call MultiboardSetItemWidth(multiboardItem, 0.08) /// @todo check it
128 call MultiboardSetItemStyle(multiboardItem, false, true)
129 call MultiboardReleaseItem(multiboardItem)
130 //set separator icon
131 set multiboardItem = null
132
133 set thistype.m_manaBar[i] = AMultiboardBar.create(thistype.m_multiboard, thistype.m_hitPointsBar[i].firstFreeField() + 1, i, 10, 0.0, true, 0.0, 0.0, 0, 0)
134 call thistype.m_manaBar[i].setAllIcons("Icons\\Interface\\Bars\\White.blp", false) //empty icons
135 call thistype.m_manaBar[i].setAllIcons("Icons\\Interface\\Bars\\Blue.blp", true)
136 set thistype.m_maxPlayers = i + 1
137 endif
138 set i = i + 1
139 endloop
140 endmethod
141
142 /**
143 * Call this method before you use this struct!
144 * Call this after a trigger sleep action, multiboard is created!
145 * Call this AFTER character creation/character class selection
146 * @param refreshRate Should be bigger than 0.0.
147 */
148 public static method init takes real refreshRate, integer barLength, string textTitle, string textLevel, string textLeftGame returns nothing
149 //static start members
150 set thistype.m_refreshRate = refreshRate
151 debug if (refreshRate <= 0) then
152 debug call thistype.staticPrint("Refresh rate is <= 0")
153 debug endif
154 set thistype.m_barLength = barLength
155 set thistype.m_textTitle = textTitle
156 set thistype.m_textLevel = textLevel
157 set thistype.m_textLeftGame = textLeftGame
158 //static members
159 call thistype.createRefreshTrigger()
160 call thistype.createMultiboard()
161 endmethod
162
163 public static method show takes nothing returns nothing
164 call EnableTrigger(thistype.m_refreshTrigger)
165 call MultiboardDisplay(thistype.m_multiboard, true)
166 endmethod
167
168 public static method showForPlayer takes player user returns nothing
169 call ShowMultiboardForPlayer(user, thistype.m_multiboard, true)
170 endmethod
171
172 public static method hide takes nothing returns nothing
173 call MultiboardDisplay(thistype.m_multiboard, false)
174 call DisableTrigger(thistype.m_refreshTrigger)
175 endmethod
176
177 public static method hideForPlayer takes player user returns nothing
178 call ShowMultiboardForPlayer(user, thistype.m_multiboard, false)
179 endmethod
180
181 public static method maximize takes nothing returns nothing
182 call EnableTrigger(thistype.m_refreshTrigger)
183 call MultiboardMinimize(thistype.m_multiboard, false)
184 endmethod
185
186 public static method minimize takes nothing returns nothing
187 call MultiboardMinimize(thistype.m_multiboard, true)
188 call DisableTrigger(thistype.m_refreshTrigger)
189 endmethod
190 endstruct
191
192 endlibrary